<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.ufida.com/lfw" prefix="lfw" %>
<%@ taglib uri="http://www.ufida.com/uif" prefix="uif" %> 
<%@ taglib uri="http://www.ufida.com/multilang" prefix="ml" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://www.ufida.com/lfwtool" prefix="lfwtool" %> 
<html>
	<head>
		<lfw:base/>
		<lfw:head/> 
		<uif:import type="2"/>
		<style>
			.grid_operatecolumn{
				width:20px;
				height:20px;
				position:absolute;
				color:#0042ae;
				font-weight:normal;
				text-decoration: underline;
			}
			a.files {
				width:150px;
				height:30px;
				overflow:hidden;
				display:block;
				border:1px solid #BEBEBE;
				text-decoration:none;
			}
			a.files:hover {
				background-color:#FFFFEE;
				background-position:0 -30px;
			}
			a.files input {
				margin-left:-320px;
				font-size:30px;
				cursor:pointer;
				filter:alpha(opacity=0);
				opacity=0;
			}
		</style>
	</head>
	<body bottommargin="0" topmargin="0" leftmargin="0" rightmargin="0" scroll=no onload="pageBodyScript()" style="background:${lfwtool:getInfo("background")}">
		<% 
			String path = "jkbxfile?type=upload&ppath=";
			path += request.getParameter("pk_jkbx");
			pageContext.setAttribute("path", path);
			String dispatchPath = request.getRequestURI() + "?" + request.getQueryString();
			pageContext.setAttribute("dispatchPath", dispatchPath);
		 %> 
		<lfw:pageModel className="nc.lfw.core.model.ConfigurationPageModel" modelId="docmanage">
			<lfw:layout type="border">
					<lfw:layoutPanel position="top">
						<table border="0px" width="100%" id="formTable">
							<form id="fileform" enctype="multipart/form-data" action="${path}" method="post" target="hidden_frame">
								<tr>
									<td align="center" width="30%">${ml:trans('yer_filemanage_pleasechoose')}</td>
									<td><a href="javascript:void(0);" class="files" id="file_list"></a></td> 
									<input type="hidden" name="type" value="upload">
									<%--
									<input type="hidden" name="dispatchPath" value="${dispatchPath}">
									--%>
									</td>
								</tr>
								<iframe name='hidden_frame' id="hidden_frame" style="display:none"></iframe>
							</form>
						</table>
					</lfw:layoutPanel>
					<lfw:layoutPanel position="center">
						<div id="centerDiv">
							<lfw:grid id="bodyTab_attachment_grid"/>
						</div> 
					</lfw:layoutPanel>
					<lfw:layoutPanel position="bottom">
						<div id="bottomDiv" style="background:#C6CEE3">
							<input type="button" value="上传新文件" id="uploadBt" disabled="disabled"/>
						</div>
					</lfw:layoutPanel>
			</lfw:layout>
		</lfw:pageModel>
	</body>
</html>
	<script type="text/javascript" src="${ROOT_PATH}/html/nodes/reqdocmanage/docmanage.js"></script>
<script><!--
	////非编辑态下只能查看
	var editAble = isEditAble();
	function isEditAble(){
		if(parent.billUI != null && 
				parent.billUI.billOperate == IBillOperate.OP_EDIT ){
			editAble = true;
		}  
		else   
			editAble = false;
		return editAble;
	}   
	
	function afterPageInit() {
		//if(!editAble){
		//	document.getElementById('file_list').disabled = true;
		//}
		//document.getElementById('file_list').disabled = true;
		var billController = new BillController("attachment_ds", false, 1, null, null, null);
		billController.setHeadGrid("bodyTab_attachment_grid");
		window.billUI = new ListUI(billController);
		$("uploadBt").onclick = function(){
			showUploadLoading();
			fu.Form.submit();
		}
	}
	
	function returnFunc(){}
	function OperatorRender(){};
	OperatorRender.render = function(rowIndex, colIndex, value, header, cell){	
		cell.style.overflow = "hidden";
		cell.style.textOverflow = "ellipsis";
		cell.style.cursor = "default";
		cell.style.textAlign = "center";
		var v = $ce("DIV");
		v.id = "div1";
		v.style.left = "0";
		v.style.top = "0";
		v.style.width = 100;
		v.style.height = 30;
		v.style.position = "absolute";
			
		var ds = $ds_attachment_ds;
		var row = ds.getRow(rowIndex);
		var state = row.getCellValue(ds.nameToIndex('state'));
		var flag = (state == "1") ? true : false;
		var isrole = row.getCellValue(ds.nameToIndex('isrole'));
		var flags = (isrole == "1") ? true : false;
		if(flag){
			//if(editAble){
			if(flags){
				v.appendChild(getDownLink(rowIndex,0));
				v.appendChild(getDelLink(rowIndex,flag,30));
			}else
				v.appendChild(getDownLink(rowIndex,15));
		}else{
			v.appendChild(getDelLink(rowIndex,flag,15));
		}
		cell.appendChild(v);
	};
	/*下载链接*/
	function getDownLink(rowIndex,left){
			var acomp = $ce("A");  
			acomp.id = "download";
			acomp.appendChild(document.createTextNode("${ml:trans('yer_filemanage_download')}"));
			acomp.className = "grid_operatecolumn";
			if(editAble) 
				acomp.style.left = left;
			else
				acomp.style.left = left;
			acomp.href = "#";
			acomp.onclick = function(e) {
				if(!e)
					e = window.event;
				try{
					download(rowIndex);
				}
				catch(error){}
				stopAll(e);
			};
			return acomp;
	}
	
	/*删除链接*/
	function getDelLink(rowIndex,flag,left){
				var acomp = $ce("A");  
				acomp.id = "delete";
				acomp.appendChild(document.createTextNode("${ml:trans('yer_filemanage_delete')}"));
				acomp.className = "grid_operatecolumn"; 
				acomp.style.left = left;
				acomp.href = "#";
				acomp.onclick = function(e) {
					if(!e)
						e = window.event;
					try{
						if(flag){
							ok4Func.param = rowIndex;
							showConfirmDialog("${ml:trans('yer_filemanage_confirmdel')}", ok4Func, null, null, null, null);
						}else{
							directDeleteFile(rowIndex);
						}
					}
					catch(error){}
					stopAll(e);
				};
				return acomp;
	}
	function ok4Func(){
		var rowIndex = ok4Func.param
		deletefile(rowIndex);
		ok4Func.param = null;
	}
	
	function directDeleteFile(rowIndex){
		var ds = $ds_attachment_ds;
		var filename = ds.getRow(rowIndex).getCellValue(0);
		ds.deleteRow(rowIndex);
		deleteFileFromDs(filename);
	}
	function deletefile(rowIndex){
		var ds = $ds_attachment_ds;
		var row = ds.getRow(rowIndex);
		var filename = row.getCellValue(ds.nameToIndex('filepath'));
		var myForm = $ce("FORM");
		myForm.id = "uploadform";
		myForm.encding = "multipart/form-data";
		document.body.appendChild(myForm);
		loadForm(myForm, "jkbxfile?type=delete&ppath=" + getParameter("pk_jkbx") + "&filename=" + encodeURIComponent(filename), fileReturnFun, null);
	}
	
	function download(rowIndex){
		var ds = $ds_attachment_ds;
		var row = ds.getRow(rowIndex);
		var filename = row.getCellValue(ds.nameToIndex('filepath'));
		var rootpath = window.globalPath;
		var url = rootpath + "/jkbxfile?type=download&ppath=" + getParameter("pk_jkbx") + "&filename=" + encodeURIComponent(filename) ;
		window.open(url,"_blank");
	}
	
	function fileReturnFun(){
		var ds = getDataset("attachment_ds");
		var loader = new DatasetLoader(ds);
		loader.setKeyValue(Dataset.MASTER_KEY);
		loader.setLoadParam("pk_jkbx=" + getParameter("pk_jkbx"));
		loader.load();
	}
	function callback(multiFileName){
		hideUploadLoading();
		if(multiFileName != '$NULL$')
			showMessageDialog(decodeURIComponent(multiFileName));
		else
			location.href = location.href
	}
--></script>